package cn.seqdata.jpa.converter;

import java.sql.Timestamp;

import javax.persistence.AttributeConverter;

import org.joda.time.LocalDateTime;

public class LocalDateTimeConverter implements AttributeConverter<LocalDateTime, Timestamp> {
	public static final LocalDateTimeConverter instance = new LocalDateTimeConverter();

	@Override
	public Timestamp convertToDatabaseColumn(LocalDateTime attribute) {
		return null != attribute ? new Timestamp(attribute.toDateTime()
			.getMillis()) : null;
	}

	@Override
	public LocalDateTime convertToEntityAttribute(Timestamp dbData) {
		return null != dbData ? new LocalDateTime(dbData.getTime()) : null;
	}
}
